package com.southern.gateway.controller;/*
 *
 *@Author:tangchao
 *@Description:
 *@Date:2022/1/24
 * */

import com.southern.gateway.base.ResultModel;
import com.southern.gateway.entity.LoginEntity;
import com.southern.gateway.feign.sysApi.SysApiLogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/auth")
@Api(tags = "system_login")
public class LoginController {
    @Autowired
    private SysApiLogin sysApiLogin;

    /**
     * 用户登录
     *
     * @param loginEntity
     * @return
     */
    @ApiOperation(value = "用户登录",httpMethod = "POST")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户名",name = "username",dataType = "String",defaultValue = "admin",required =true,paramType = "query"),
            @ApiImplicitParam(value = "密码",name = "pwd",dataType = "String",defaultValue = "admin",required =true,paramType = "query")
    })
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public ResultModel login(LoginEntity loginEntity)
    {
        return ResultModel.success(sysApiLogin.login(loginEntity.getUsername(),loginEntity.getPwd()));
    }

    /**
     * 用户退出登录,删除token的redis值
     *
     * @return
     */
    @ApiOperation(value = "用户退出登录",httpMethod = "POST")
    @RequestMapping(value = "/logout", method = RequestMethod.POST)
    public ResultModel logout() {
        return ResultModel.success(sysApiLogin.logout());
    }

    /**
     * 校验token的有效性
     *
     * @return
     */
    @ApiOperation(value = "校验token的有效性",httpMethod = "GET")
    @RequestMapping(value = "/checkTokenIsEffect", method = RequestMethod.GET)
    public ResultModel checkTokenIsEffect(String token) {
        return ResultModel.success(sysApiLogin.checkTokenIsEffect(token));
    }

}
